class Admin::PeopleLicensesController < ApplicationController
  before_filter :find_person
  
  def new
    @people_license = PeopleLicense.new
  end

  def edit
    @people_license = @person.people_licenses.find(params[:id])
  end

  def create
    @people_license = PeopleLicense.new(params[:people_license])
    if (@person.people_licenses << @people_license)
      redirect_to admin_person_url(@person)
    else
      render :action => new
    end
  end

  def update
    @people_license = @person.people_licenses.find(params[:id])
    if @people_license.update_attributes(params[:people_license])
      redirect_to admin_person_url(@person)
    else
      render :action => edit
    end
  end

  def destroy
    people_license = @person.people_licenses.find(params[:id].to_i)
    @person.people_licenses.delete(people_license)
    redirect_to admin_person_url(@person)
  end

  private
  def find_person
    @person_id = params[:person_id]
    redirect_to admin_people_url unless @person_id
    @person = Person.find(@person_id)
  end
end
